<!DOCTYPE html>
<html>

<head>
    <title>图片分享</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/js/plugins/choosen/component-chosen.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/editTravels.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script src="/js/plugins/eleditor/Eleditor.min.js"></script>
    <script src="/js/plugins/eleditor/webuploader.min.js"></script>
    <script src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
    <script src="/js/plugins/choosen/chosen.jquery.js"></script>
    <script type="text/javascript"
            src="http://api.map.baidu.com/api?v=2.0&ak=ZKmHNO2MuHvb5EyXHse4kPDGc45buOo9"></script>
    <script src="/js/common.js"></script>
    <!--一\照片上传-->
    <script>
        $(function () {
            $('#changeBtn').click(function () {
                $('#imageFile').click();
            });
            $('#imageFile').change(function () {
                $('#coverForm').ajaxSubmit(function (data) {
                    if (data.status === 1) {
                        $('#coverUrl').prop('src', data.url);
                    }
                });
            });
        });
    </script>
    <!--二\定位-->
    <script>
        $(function () {
            var city;//城市
            var locationL = 121.482635;//经度
            var locationD = 31.246537;//纬度
            $("#locationBtn").click(function () {

                // 百度地图API功能
                var map = new BMap.Map("allmap");
                var point = new BMap.Point(locationL, locationD);
                map.centerAndZoom(point, 12);

                //定位
                var geolocation = new BMap.Geolocation();
                geolocation.getCurrentPosition(function (r) {
                    if (this.getStatus() === BMAP_STATUS_SUCCESS) {
                        //更新定位参数
                        updataLocateParams(r.address.city, r.point.lng, r.point.lat);
                        console.log(r);
                        point = new BMap.Point(locationL, locationD);
                        map.centerAndZoom(point, 16);
                        //定位点标记
                        var marker = new BMap.Marker(point);        // 创建标注
                        map.addOverlay(marker);
                        marker.enableDragging(); //可以拖动
                        marker.addEventListener("dragend", function (e) {
                            console.log(("当前位置：" + e.point.lng + ", " + e.point.lat));
                            updataLocateParams(e.currentTarget.map.Xg, e.point.lng, e.point.lat);
                        });
                        //定位
                    }
                    else {
                        alert('定位失败,请拖动定位');
                    }
                }, {enableHighAccuracy: true});
            });
        });

        /**
         * 更新定位参数
         * @param cityName
         * @param l
         * @param d
         */
        function updataLocateParams(cityName, l, d) {
            city = cityName;
            locationL = l;
            locationD = d;
            $("#locationBtn small").html(city);
        }
    </script>
    <!--三\图片发布-->
    <script>
        $(function () {
            $('#release').click(function () {
                /*保存数据*/
                $.ajax({
                    url: "/pictureShare",
                    type: "Post",
                    data: {
                        title: $("#title").val(), coverUrl: $('#coverUrl').attr('src')
                        , locationL: locationL, locationD: locationD, cityName: city
                    },
                    success: function (result) {
                        console.log(result);
                        if (result.success) {
                            window.history.back();
                        }
                    }
                });
            });
        })
    </script>
</head>
<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:window.history.go(-1);">
                <span><i class="fa fa-times"></i></span>
            </a>
        </div>
        <div class="col-5"></div>
        <div class="col" style="text-align: right;">
            <i class="fa fa-check" id="release"><span>发布</span></i>
        </div>
    </div>
</div>


<div class="travels form-group">
    <div class="cover">
        <img id="coverUrl" width="100%" render-src="coverUrl" height="200px"/>
        <form id="coverForm" action="/images" method="post" enctype="multipart/form-data">
            <input type="file" name="file" style="display: none" accept="image/gif,image/jpeg,image/jpg,image/png"
                   id="imageFile"/>
            <button type="button" class="btn" id="changeBtn">
                <i class="fa fa-pencil-square-o"></i>
                <small>添加图片</small>
            </button>
        </form>
    </div>
    <div class="title">
        <textarea class="form-control" id="title" name="title" placeholder="请输入图片简介"></textarea>
    </div>
    <div class="location">
        <button type="button" class="btn form-control" id="locationBtn">
            <i class="fa fa-location-arrow"></i>
            <small>定位</small>
        </button>
    </div>
    <!--定位map-->
    <div id="allmap" style="height: 200px;"></div>
</div>


</body>

</html>